// 获取文件夹名称
const pageName = process.argv[2] && process.argv[2].trim();
const indexContent = `
import "lib-flexible"
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
`

const vueContent = `
<template>
 <div class="${pageName}-wrapper">
 
 </div>
</template>

<script>
export default {
  name: "App",
};
</script>

<style lang="less" scoped>

</style>
`

const htmlContent = `
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="icon" href="<%= BASE_URL %>favicon.ico">
  <title>
    <%= htmlWebpackPlugin.options.title %>
  </title>
</head>

<body>
  <noscript>
    <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
        Please enable it to continue.</strong>
  </noscript>
  <div id="app"></div>
  <!-- built files will be auto injected -->
</body>

</html>`

if (pageName === undefined) {
  console.log("请输入文件名");
} else {
  const fs = require("fs");

  !fs.existsSync(`./src/entry/${pageName}`) && fs.mkdirSync(`./src/entry/${pageName}`);
  fs.writeFileSync(`./src/entry/${pageName}/index.js`, indexContent);
  fs.writeFileSync(`./src/entry/${pageName}/App.vue`, vueContent);
  fs.writeFileSync(`./public/${pageName}.html`, htmlContent);

  console.log(pageName + "页面创建成功");
}